package com.boc.ewr.business.service.impl;

import com.boc.ewr.business.entity.AcctDtlClassC;
import com.boc.ewr.business.entity.AcctDtlClassD;
import com.boc.ewr.business.mapper.AcctDtlClassCMapper;
import com.boc.ewr.business.service.IAcctDtlClassCService;
import com.boc.ewr.business.service.IAcctDtlClassDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @Description: C类账户明细
 * @Author: jeecg-boot
 * @Date:   2023-05-26
 * @Version: V1.0
 */
@Service
public class AcctDtlClassCServiceImpl extends ServiceImpl<AcctDtlClassCMapper, AcctDtlClassC> implements IAcctDtlClassCService {

    @Autowired
    IAcctDtlClassDService acctDtlClassDService;

    @Autowired
    AcctDtlClassCMapper acctDtlClassCMapper;
    //产生数据
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createInfo() {
        List<AcctDtlClassC> cList = acctDtlClassCMapper.creatInfo();
        List<AcctDtlClassD> dList = acctDtlClassDService.list();
        //获取存在D类的账户
        Set<String> acctDList = dList.stream().map(AcctDtlClassD::getAcctNo).collect(Collectors.toSet());//D类
        List<String> acctList = new ArrayList<>(acctDList);
        //去掉D类（D1、D2、D3）
        List<AcctDtlClassC> result = cList.stream().filter(it -> !acctList.contains(it.getAccNo())).collect(Collectors.toList());
        saveBatch(result);
    }
}
